﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using He.Web.UI;
using He.Common;

namespace He.Web.manage.feedback
{
    public partial class list : He.Web.UI.Manage
    {
        protected int pageSize = 12;
        protected int page;
        protected int pcount;
        public string pos_mark;
        protected void Page_Load(object sender, EventArgs e)
        {
            pos_mark = GetString("pos_mark");
            page = GetInt("page", 0);

            if (!IsPostBack)
            {
                chkLoginLevel("view" + pos_mark);

                CookieHelper.Set("LastListUrl", Request.RawUrl);    //保存最后一次访问的列表页Url

                RpgBind();
            }
        }

        #region 数据绑定
        private void RpgBind()
        {
            BLL.feedback bll = new BLL.feedback();
            string strWhere = CombPlugSqlTxt(pos_mark, lang);
            rptInfo.DataSource = bll.GetPageList(pageSize, page, strWhere, "Id desc");
            rptInfo.DataBind();
            pcount = bll.GetRecordCount(strWhere);
        }
        #endregion

        //删除
        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("del" + pos_mark);
            BLL.feedback bll = new BLL.feedback();
            for (int i = 0; i < rptInfo.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptInfo.Items[i].FindControl("Check");
                int id = int.Parse(((HiddenField)rptInfo.Items[i].FindControl("HiddenId")).Value);
                if (cb.Checked)
                {
                    Model.feedback model = bll.GetModel(id);
                    bll.Delete(id);
                }
            }
            SaveLogs("[留言板管理]批量删除");
            JscriptPrint("批量删除成功啦！", Request.RawUrl, "Success");
        }
        //审核
        protected void lbtnAudit_Click(object sender, EventArgs e)
        {
            chkLoginLevel("edit" + pos_mark);
            BLL.feedback bll = new BLL.feedback();
            for (int i = 0; i < rptInfo.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptInfo.Items[i].FindControl("Check");
                int id = int.Parse(((HiddenField)rptInfo.Items[i].FindControl("HiddenId")).Value);
                if (cb.Checked)
                {
                    He.Model.feedback model = bll.GetModel(id);
                    bll.UpdateField(id, string.Format("status={0}", (int)Enums.AuditStatus.已审核));
                }
            }
            SaveLogs("[留言板管理]批量审核");
            JscriptPrint("批量审核成功啦！", Request.RawUrl, "Success");
        }

    }
}
